﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Xml.Linq;
using Microsoft.MediaCenter.UI;
using System.Diagnostics;

namespace Playkanaler
{

    public class Item : ModelItem
    {
        string title = "";
        string path = "";

        Dictionary<string, object> attributes = new Dictionary<string, object>();

        public Item Update(Item item)
        {
            int ind = Index;
            string pa = Path;
            DateTime d = new DateTime();
            if (Attributes.ContainsKey("Added"))
            {
                d = (DateTime)Attributes["Added"];
            }
            foreach (KeyValuePair<string, object> kvp in item.Attributes)
            {
                if (Attributes.ContainsKey(kvp.Key))
                {
                    if (item.Attributes[kvp.Key].ToString() != "")
                    {
                        Attributes[kvp.Key] = item.Attributes[kvp.Key];
                    }
                }
            }
            Attributes["Added"] = d;
            Index = ind;
            Path = pa;

            Item ii = new Item();
            ii.Attributes = Attributes;

            return ii;

        }

        public string Year
        {
            // get { return year; }
            // set { year = value; }
            get { return (string)Attributes["Year"]; }
            set { Attributes["Year"] = value; }
        }

        int index;
        public string Title
        {
            get
            {
                //return title;
                return (string)attributes["Title"];
            }
            set
            {
                title = value;
                attributes["Title"] = value;

            }
        }
        Microsoft.MediaCenter.UI.Image image;
        string imageUrl = "";
        public string ImageUrl
        {
            get
            {
                
                return (string)attributes["ImageUrl"];

            }
            set
            {

               
                try
                {

                    attributes["ImageUrl"] = value;
                
                }
                catch { }

            }
        }
        public override string ToString()
        {
            return Title;
        }

        virtual public Microsoft.MediaCenter.UI.Image Image
        {
            get
            {

                if (ImageUrl != "")
                {


                    return new Microsoft.MediaCenter.UI.Image(ImageUrl);

                }


                return image;
            }

        }

        public Dictionary<string, object> Attributes
        {
            get { return attributes; }
            set { attributes = value; }
        }

        public string Path
        {
            get
            {
                //return path;
                return (string)attributes["Path"];


            }
            set
            {
                // path = value;
                attributes["Path"] = value;


            }
        }


        string description = "";
        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }
        public int Index
        {
            get
            {
                return index;
            }
            set
            {
                index = value;
            }
        }



        void fill()
        {
            attributes.Add("Title", "");
            attributes.Add("ImageUrl", "");
            attributes["Path"] = "";
            Attributes["Year"] = "";
        }


        public Item()
        {
            fill();
        }
        public Item(string Title, int indx)
        {
            fill();

            this.Title = Title;
            this.index = indx;

        }
        public Item(string Title, int indx, string bild)
        {
            fill();

            this.Title = Title;
            this.index = indx;


            ImageUrl = bild;
        }

        public bool MetaDataLoaded
        {
            get
            {
                return metadataloaded;
            }
            set
            {
                metadataloaded = value;
            }
        }
        bool metadataloaded = false;

        public virtual void LoadMetaData()
        {

        }


    }




}
